/**
 * @author LKQ
 * @date 2022/2/28 10:58
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int numRookCaptures(char[][] board) {
        int n = 8;
        int[][] dirs = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
        // 首先获取车的位置
        int[] loc = {0, 0};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (board[i][j] == 'R') {
                    loc = new int[]{i, j};
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 4; i++) {
            int ni = loc[0] + dirs[i][0], nj =  loc[1] + dirs[i][1];
            // 四个方向，出界或碰到卒，象停止
            while (ni >= 0 && ni < 8 && nj >= 0 && nj < 8 && board[ni][nj] == '.') {
                ni += dirs[i][0];
                nj += dirs[i][1];
            }
            if (ni >= 0 && ni < 8 && nj >= 0 && nj < 8 && board[ni][nj] == 'p') {
                ans++;
            }
        }
        return ans;
    }
}
